def call(Map config) {
    log.info("部署应用")
    container('maven') {
        def projectpom = readMavenPom file: 'pom.xml'
        def projectArtifactId = projectpom.getArtifactId()
        def PREVIEW_NAMESPACE = "preview"
        def TEST_NAMESPACE = "test"
        def DEV_NAMESPACE = "dev"
        def BUG_NAMESPACE = "bug"
        def DEMO_NAMESPACE = "demo"
        def spaces = ' '
        CHARTMUSEUM_CREDS = credentials('chartmuseum')

        if(dev_spaces == 'true'){
            spaces = DEV_NAMESPACE
        } else if (preview_spaces == 'true'){
            spaces = PREVIEW_NAMESPACE
        } else if (bug_spaces == 'true'){
            spaces = BUG_NAMESPACE
        } else if (test_spaces == 'true'){
            spaces = TEST_NAMESPACE
        } else if (demo_spaces == 'true'){
            spaces = DEMO_NAMESPACE
        }
//        log.info(spaces)
//        log.info(config.deployEnable)
//        log.info(config.jvmCacertsEnable)
//        log.info(BRANCH_NAME.startsWith('master'))
        if(spaces != ' ' && config.deployEnable){
            if(config.jvmCacertsEnable){
                createJvmCacerts.deploySecret(spaces,projectArtifactId)
            }
            if (spaces == TEST_NAMESPACE && BRANCH_NAME.startsWith('master')){
                dir ("./k8sconfig/charts/${projectArtifactId}") {
//                    cred = creds.findCredsById('chartmuseum')
//                    CHARTMUSEUM_CREDS_USR = cred.password
//                    CHARTMUSEUM_CREDS_USR = cred.username
                    //迁移到了deployImage.groovy中了
                    //sh "export FILE_NAME=$projectArtifactId && export NAMESPACE=$spaces && make tag"

                    //迁移到了deployImage.groovy中了
                    //sh "export FILE_NAME=${projectArtifactId} && export ALIYUN=${config.deploy_aliyun} && make release"

                    //FIXME 统一输出到指定目录
//                    utilities.deploy_app(spaces,projectArtifactId)
                    sh "helm template -n $spaces --output-dir . . "
                    //当前目录
                    sh "kubectl apply -f ./$projectArtifactId/templates/ -n $spaces "
                    //删除容器重新加载新部署的镜像
                    sh "kubectl get pod -n $spaces  |grep $projectArtifactId | awk '{print \$1}'|xargs -I {} kubectl delete pod -n $spaces {} --force --grace-period=0"
                }
            }else if(BRANCH_NAME.startsWith('PR-')){
                dir ("./k8sconfig/charts/$spaces") {
                    sh "export FILE_NAME=$projectArtifactId && export NAMESPACE=$spaces && make preview"

                    //FIXME 统一输出到指定目录
//                    utilities.deploy_app(spaces,projectArtifactId)
                    sh "helm template -n $spaces --output-dir . . "
                    //当前目录--环境目录下执行
                    sh "kubectl apply -f ./$spaces/charts/$projectArtifactId/templates/ -n $spaces "
                    //删除容器重新加载新部署的镜像
                    sh "kubectl get pod -n $spaces  |grep $projectArtifactId | awk '{print \$1}'|xargs -I {} kubectl delete pod -n $spaces  {} --force --grace-period=0"
                    sh "chown -R 10000:10000 ../$spaces"
                }
            }
        }else {
            log.info("未匹配到任何部署环境，跳过部署操作。")
        }
    }
}